var http = require('http').Server();
var io = require('socket.io')(http);
var Redis = require('ioredis');

var redis = new Redis(6002,'localhost',{
    password:'redis'
});

var channel = 'channel';


redis.subscribe( channel );

redis.on('message',function(channel , message){
    console.log(channel + ":" + message);
    message = JSON.parse(message);
    io.emit("myevent" , message.data);
});

io.on('connection', function (socket) {
    // console.log(socket);

    socket.emit('news', { hello: 'world' });
    socket.on('tevent', function (data) {
        console.log(data);
    });

});

http.listen(9003,function(){
    console.log('server is listen at http://localhost:9003');
});